package cn.tedu.collection;

import org.junit.Test;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author :Colin
 * @version 创建时间: 2021/7/1 20:35
 */
public class TestCollection {
    public static void main(String[] args) {
        Collection <Integer> c=  new ArrayList();
        c.add(10);
        c.add(11);
        c.add(12);
        c.add(13);
        c.add(14);
        System.out.println(c);
        System.out.println(c.remove(10));
        System.out.println(c);
        System.out.println(c.isEmpty());
        System.out.println(c.hashCode());
        System.out.println(c.contains(10));
        System.out.println(c.contains(11));
        System.out.println(c.equals(10));
        Collection<Integer> d= new ArrayList<>();
        d.add(11);
        d.add(12);
        d.add(13);
        d.add(14);
        System.out.println(c.equals(d));
        System.out.println(c.size());
        System.out.println("集合与集合之间关系");
        System.out.println(c.addAll(d));
        System.out.println(c);
        System.out.println(d);
        System.out.println(d.remove(11));
        System.out.println(c.removeAll(d));
        System.out.println(c);
        System.out.println(c.remove(11));
        System.out.println(c);//11
        System.out.println(c.isEmpty());
        System.out.println(d);
        System.out.println(d.add(11));
        System.out.println(d);//12 13 14 11
//        System.out.println(d.containsAll(c));
//        System.out.println(c.containsAll(d));
        System.out.println("cd交集"+c.retainAll(d));
        System.out.println(d);
        System.out.println(c);
        System.out.println("d c交集"+d.retainAll(c));
        System.out.println(d);
        System.out.println(c);
        Collection <Integer> e=  new ArrayList();
        e.add(10);
        Collection <Integer> f=  new ArrayList();
        f.add(11);
        System.out.println(f);//11
        System.out.println(f.retainAll(e));
        System.out.println(e);
        System.out.println(f);
    }
    @Test
    public void testiterater(){
        Collection<Integer> a = new ArrayList<>();
        System.out.println(a);
        //a.add(1);
        while(a.size()<=9){
        a.add((int)(Math.random()*10));
        }
        System.out.println(a.size());
        System.out.println(a);
        Iterator<Integer> it =a.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
    }

}
